function exportToCSV(header, data, fileName) {
    const workbook = new ExcelJS.Workbook();
    const worksheet = workbook.addWorksheet("My Sheet");
    worksheet.addRow(header);
    data.forEach((row) => {
      worksheet.addRow(row);
    });
    workbook.xlsx
      .writeBuffer()
      .then(function (buffer) {
        const blob = new Blob([buffer], {
          type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        });
        const link = document.createElement("a");
        link.href = URL.createObjectURL(blob);
        link.download = fileName + ".xlsx";
        document.body.appendChild(link);
        link.click();
      })
      .catch(function (err) {
        console.log("Error writing file", err);
      });
  }

  function formatDate(timestamp) {
    // 创建一个新的 Date 对象，参数为时间戳乘以 1000 转换成毫秒
    const date = new Date(timestamp * 1000);
    
    // 获取年、月、日、时、分、秒
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');
    
    // 返回格式化后的日期字符串
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

// 显示遮罩层
function showLoadingMask() {
  let loadingMask = document.getElementById('loadingMask');
  if (!loadingMask) {
      // 如果遮罩层不存在，则创建
      loadingMask = document.createElement('div');
      loadingMask.setAttribute('class', 'ey-loading-mask');
      loadingMask.setAttribute('id', 'loadingMask');
      let loadingIcon = document.createElement('div');
      loadingIcon.setAttribute('class', 'ey-loading-icon');
      loadingIcon.innerText = '数据导出中,请等待...';
      loadingMask.appendChild(loadingIcon);
      document.body.appendChild(loadingMask);
  }
  loadingMask.style.display = 'block';
}

// 隐藏遮罩层
function hideLoadingMask() {
  let loadingMask = document.getElementById('loadingMask');
  if (loadingMask) {
      loadingMask.style.display = 'none';
  }
}

function updateUrlParameter(url, key, value) {
  // 解析 URL，获取其组成部分
  let urlParts = url.split('?');
  let baseUrl = urlParts[0];
  let queryString = urlParts[1] || ''; // 查询字符串部分

  // 解析查询字符串为键值对
  let queryParams = {};
  if (queryString) {
      let queryParamsArray = queryString.split('&');
      queryParamsArray.forEach(function(param) {
          let paramParts = param.split('=');
          queryParams[paramParts[0]] = paramParts[1];
      });
  }

  // 更新或添加键值对
  queryParams[key] = value;

  // 构建新的查询字符串
  let updatedQueryString = Object.keys(queryParams).map(function(paramKey) {
      return paramKey + '=' + queryParams[paramKey];
  }).join('&');

  // 更新 URL
  let updatedUrl = baseUrl + '?' + updatedQueryString;

  return updatedUrl;
}

function createEyProgress() {
  // 创建遮罩层和进度条
  let overlay = document.createElement('div');
  overlay.className = 'ey-overlay';
  let progressBar = document.createElement('div');
  progressBar.className = 'ey-progress-bar';
  let progress = document.createElement('div');
  progress.className = 'ey-progress';
  let progressTitle = document.createElement('div');
  progressTitle.className = 'ey-progress-title';
  progressBar.appendChild(progress);
  progressBar.appendChild(progressTitle);
  overlay.appendChild(progressBar);
  document.body.appendChild(overlay);
}
// 显示遮罩层和进度条
function showEyProgress() {
  document.querySelector('.ey-overlay').style.display = 'block';
}

// 隐藏遮罩层和进度条
function hideEyProgress() {
  document.querySelector('.ey-overlay').style.display = 'none';
}

// 设置进度条的进度
function setEyProgress(percent) {
  var progress = document.getElementsByClassName('ey-progress')[0];
  progress.style.width = percent + '%';
  updateEyProgressTitle(percent + '%');
}

// 设置带标题的进度条的进度
function setEyProgressWithTitle(percent, title) {
  var progress = document.getElementsByClassName('ey-progress')[0];
  progress.style.width = percent + '%';
  updateEyProgressTitle(title);
}

// 更新进度条标题
function updateEyProgressTitle(title) {
  var progressTitle = document.getElementsByClassName('ey-progress-title')[0];
  progressTitle.innerText = title;
}